<?php
namespace App\Models\Relations;

use App\Models\Attachment;
/**
 *
 * @author Joker
 *        
 */
trait AttachmentTrait
{
    /**
     * 获取封面图片 一对一关联 
     */
    public function attachment()
    {
        return $this->hasOne('App\Models\Attachment','aid','thumb');
    }
    
    /**
     * 获取封面图片，根据表
     * @param  $appTable 所属表
     * @param  $appId id
     */
    public function getAttachment($appTable,$appId) 
    {
        return Attachment::where(array('app'=>$appTable,'app_id'=>$appId))->orderBy('created_at','desc')->first();
    }
}